home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / XPK / Source / test / testFHUnpack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-15  |  2.2 KB  |  97 lines

  1. #define NAME     "testFHUnpack"
  2. #define REVISION "0"
  3. #define ENDCODE_NOCTRLC
  4.  
  5. /* Programmheader
  6.  
  7.     Name:        testFHUnpack
  8.     Author:        SDI
  9.     Distribution:    PD
  10.     Description:    easy file to file unpacker using FH's
  11.     Compileropts:    -
  12.     Linkeropts:    -l xpkmaster amiga
  13.  
  14.  1.0   02.04.97 : first version
  15. */
  16.  
  17. /* NOTE: You may pass option OFFSET, when packed data does not start at
  18.    really file start */
  19.  
  20. #include <pragma/exec_lib.h>
  21. #include <pragma/dos_lib.h>
  22. #include <pragma/xpkmaster_lib.h>
  23. #include "SDI_defines.h"
  24.  
  25. #ifdef __MAXON__
  26.   #define __asm
  27.   #define __saveds
  28. #endif
  29.  
  30. struct Library        *XpkBase    = 0;
  31. ULONG            DosVersion    = 37;
  32. struct RDArgs        *rda        = 0;
  33. ULONG            fhin        = 0;
  34. ULONG            fhout        = 0;
  35.  
  36. #define PARAM "FROM/A,TO/A,OFFSET/K/N"
  37.  
  38. LONG __asm __saveds chunkfunc(register __a1 struct XpkProgress *prog)
  39. {
  40.   switch(prog->xp_Type)
  41.   {
  42.   case XPKPROG_START: PutStr("Start: "); break;
  43.   case XPKPROG_MID: PutStr("\rMid  : "); break;
  44.   case XPKPROG_END: PutStr("\rEnd  : "); break;
  45.   }
  46.  
  47.   if(prog->xp_Type != XPKPROG_END)
  48.     Printf("%4s: %-8s (%3ld%% done, %2ld%% CF, %6ld cps) %s",
  49.       prog->xp_PackerName, prog->xp_Activity, prog->xp_Done,
  50.       prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
  51.   else
  52.     Printf("%4s: %-8s (%3ldK, %2ld%% CF, %6ld cps) %s\033[K\n",
  53.       prog->xp_PackerName, prog->xp_Activity, prog->xp_ULen >> 10,
  54.       prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
  55.  
  56.   Flush(Output());
  57.   return (LONG) SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C;
  58. }
  59.  
  60. struct Hook chunkhook = { {0}, (ULONG (*)()) chunkfunc};
  61.  
  62. void main(void)
  63. {
  64.   ULONG err;
  65.  
  66.   struct {
  67.     STRPTR from;
  68.     STRPTR to;
  69.     ULONG  *offset;
  70.   } args = {0, 0, 0};
  71.  
  72.   if(!(rda = ReadArgs(PARAM, (LONG *) &args, 0)) ||
  73.   !(XpkBase = OpenLibrary(XPKNAME, 4)) ||
  74.   !(fhin = Open(args.from, MODE_OLDFILE)) ||
  75.   !(fhout = Open(args.to, MODE_NEWFILE)) ||
  76.   (args.offset && Seek(fhin, *args.offset, OFFSET_BEGINNING) == -1))
  77.     End(RETURN_FAIL);
  78.  
  79.   if((err = XpkUnpackTags(XPK_InFH, fhin, XPK_OutFH, fhout,
  80.   XPK_ChunkHook, &chunkhook, TAG_DONE)))
  81.   {
  82.     XpkPrintFault(err, "Can't XpkUnpack");
  83.     End(RETURN_FAIL);
  84.   }
  85.  
  86.   End(RETURN_OK);
  87. }
  88.  
  89. void end(void)
  90. {
  91.   if(fhout)    Close(fhout);
  92.   if(fhin)    Close(fhin);
  93.   if(XpkBase)    CloseLibrary(XpkBase);
  94.   if(rda)    FreeArgs(rda);
  95. }
  96.  
  97.